#ifndef DEBUG_H
#define DEBUG_H
/* 
 * Interesting things comes from here
 */

#define debug(LVL) __debug(LVL, qDebug)
#define dbg debug(DBG_5)
#define info debug(INFO)
#define warn __error(WARNING)
#define err __error(ERROR)
#define crit __error(CRITICAL)
#define fatal __error(FATAL)

/* 
 * There is no interestings things anymore.
 * sorry.
 */

#include <QtDebug>

#define F_C "\033[5;41m"
#define C_C "\033[1;41m"
#define E_C "\033[1;31m"
#define W_C "\033[1;33m"
#define I_C "\033[1;34m"
#define D_1 "\033[1;32m"
#define D_2 "\033[0;32m"
#define D_3 "\033[1;37m"
#define D_4 "\033[0;37m"
#define D_5 "\033[37m"
#define WHITE "\033[0m"


#define MAXLEVEL 10

namespace {
	char* level[MAXLEVEL] = {
		C_C""F_C"Fatal!"WHITE,
		C_C"Critical"WHITE,
		E_C"Error"WHITE,
		W_C"Warning"WHITE,
		I_C"Info"WHITE,
		D_1"dbg1"WHITE,
		D_2"dbg2"WHITE,
		D_3"dbg3"WHITE,
		D_4"dbg4"WHITE,
		D_5"dbg5"WHITE
		};
	enum levels {
		FATAL = 0,
		CRITICAL,
		ERROR,
		WARNING,
		INFO,
		DBG_1,
		DBG_2,
		DBG_3,
		DBG_4,
		DBG_5
	};
};

#define PREDIC_LEVEL(LVL) QString("%1:%2[%3]:").arg(__FILE__).arg(__LINE__).arg(level[LVL])
#ifdef DEBUG // IF NO DEBUG THEN THERE IS NO DEBUG
#ifdef NOISY_DEBUG
#include <QTime>
#define TIMESTAMP QTime::currentTime().toString("HH:mm:ss.zzz")
#define PREDICAT TIMESTAMP << "In file" << __FILE__ << "line" << __LINE__ << "function" << __FUNCTION__
#define PREDIC_LEVEL(LVL) PREDICAT << "[" << level[LVL] << "]\n"
#endif //NOISY_DEBUG
#endif //DEBUG

#define ALLOWED_DEBUG_LEVEL INFO
#ifdef DEBUG // IF NO DEBUG THEN THERE IS NO DEBUG
#define MAXALLOWEDLEVEL MAXLEVEL
#else //DEBUG
#define MAXALLOWEDLEVEL INFO
#endif //DEBUG

#define __debug(LVL, FUNC) if ( LVL <= ALLOWED_DEBUG_LEVEL && LVL <= MAXALLOWEDLEVEL ) FUNC() << PREDIC_LEVEL(LVL)
#define __error(LVL) __debug(LVL, qWarning)



#endif //DEBUG_H
